﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;
using System.Data;
using System.Data.Common;

public partial class Admin_AdminLayout : System.Web.UI.MasterPage
{
    protected void Page_Load(object sender, EventArgs e)
    {
		if(!IsPostBack)
		{
			DbCommand cmd = GenericDataAccess.CreateCommand();
			cmd.CommandText = "EF_GetUserProfile";

			DbParameter userParam = cmd.CreateParameter();
			userParam.ParameterName = "@UserID";
			userParam.Value = Membership.GetUser().ProviderUserKey;
			cmd.Parameters.Add(userParam);

			DataTable table = new DataTable();
			table = GenericDataAccess.ExecuteSelectCommand(cmd);
			if(table.Rows.Count > 0)
			{
				UserWelcome.FormatString = "<span class=\"glyphicon glyphicon-user\"></span>" + table.Rows[0]["LastName"].ToString() + " " + table.Rows[0]["FirstName"].ToString();
			}
			UserLogout.LogoutText = "<span class=\"glyphicon glyphicon-log-out\"></span>ចាកចេញ";

			CountOrder.Text = CountOrderItem();
		}
    }

	// returns total count of all order
	protected string CountOrderItem()
	{
		DbCommand cmd = GenericDataAccess.CreateCommand();
		cmd.CommandText = "EF_CountOrderNotCompleted";
		return GenericDataAccess.ExecuteScalar(cmd);
	}
}